<?php include $this->getViewFile('/common/Head') ?>
<body class="J_scroll_fixed">
  <style type="text/css">
    .color{
      color:red;
    }
  </style>

  <div class="wrap J_check_wrap">
    <?php include $this->getViewFile('/common/Nav') ?>


     <!-- 搜索 -->
    <div class="h_a">查找</div>
    <?php $objForm = $this->beginWidget( 'CActiveForm', array('id' => 'searchForm','method' => 'get','action' => $this->createUrl('countsale')) ); ?>
      <div class="search_type cc mb10">
           <div class="mb10">
        统计时间范围：
        <input type="text" name="start_time" class="input length_2 J_date" value="<?php echo $start_time?>" placeholder="选择起始时间">
        -
        <input type="text" class="input length_2 J_date" name="end_time" value="<?php echo $end_time?>" placeholder="选择结束时间">       
        <button class="btn">搜索</button>
          


          </div>
      </div>
    <?php $this->endWidget(); ?>


    <div class="mb10">
      统计结果
    </div>

    <form name="myform" action="" method="post" class="J_ajaxForm">
      <div class="table_list">
        <table width="100%" cellspacing="0">
          <thead>
            <tr>
              <td width="5%" align="center">类目</td>
              <td width="5%" align="center">审核人</td>
              <td width="5%" align="center">报名产品总数</td>
              <td width="5%" align="center">待审核</td>
              <td width="5%" align="center">审核通过</td>
              <td width="5%" align="center">审核不通过</td>
              <td width="5%" align="center">邮寄样品</td>
              <td width="5%" align="center">收到样品</td>
              <td width="5%" align="center">不足10单</td>
              <td width="5%" align="center">超过150单</td>
              <td width="10%" colspan="2" align="center">
                <table>
                  <tr>
                    <td colspan="2" align="center">10元以内</td>
                  </tr>
                  <tr>
                    <td>销量</td>
                    <td>上架数</td>
                  </tr>
                </table>
              </td>
              <td width="10%" colspan="2" align="center">
                <table>
                  <tr>
                    <td colspan="2" align="center">10-20元</td>
                  </tr>

                  <tr>
                    <td>销量</td>
                    <td>上架数</td>
                  </tr>
                </table>
              </td>
              <td width="10%" colspan="2" align="center">
                <table>
                  <tr>
                    <td colspan="2" align="center">20-30元</td>
                  </tr>

                  <tr>
                    <td>销量</td>
                    <td>上架数</td>
                  </tr>
                </table>
              </td>
              <td width="10%" colspan="2" align="center">
                <table>
                  <tr>
                    <td colspan="2" align="center">30元以上</td>
                  </tr>

                  <tr>
                    <td>销量</td>
                    <td>上架数</td>
                  </tr>
                </table>
              </td>
              <td width="5%" align="center">总销量</td>
              <td width="5%" align="center">上架数</td>
            </tr>
          </thead>
          <tbody id="tbody">



             <?php foreach($data as $cat_id => $rss){ ?>
             <?php $count = count($rss['data']);$key = 0;$key1 = 0;?>
             <?php foreach($rss['data'] as $admin_id => $rs){ ?>
              <tr data_admin_id="<?php echo $admin_id; ?>">
                <?php if($key == 0){ ?>
                <td  class="rowspan" rowspan="<?php echo $count ?>" align="center"><?php echo $rss['name'] ?></td>
                <?php $key = 1;} ?> 


                  <td  align="center"><?php echo $rs['username'] ?></td>


                  <?php if($key1 == 0){ ?>
                  <td  class="rowspan" rowspan="<?php echo $count ?>" align="center"><?php echo $rss['count'] ?></td>
                  <?php $key1 = 1;} ?> 


                  <td  align="center"><?php echo $rs['status_0'] ?></td>
                  <td  align="center"><?php echo $rs['status_1'] ?></td>
                  <td  align="center"><?php echo $rs['status_2'] ?></td>
                  <td  align="center"><?php echo $rs['isdelivery_12'] ?></td>
                  <td  align="center"><?php echo $rs['isdelivery_2'] ?></td>
                  <td  align="center"><?php echo $rs['turnover_l_10'] ?></td>
                  <td  align="center"><?php echo $rs['turnover_g_150'] ?></td>

                  <td  width="5%" align="center"><?php echo $rs['promo_price_l_10'] ?></td>
                  <td  width="5%" align="center"><?php echo $rs['shangjia_l_10'] ?></td>
                  <td  width="5%" align="center"><?php echo $rs['promo_price_10_20'] ?></td>
                  <td  width="5%" align="center"><?php echo $rs['shangjia_10_20'] ?></td>
                  <td  width="5%" align="center"><?php echo $rs['promo_price_20_30'] ?></td>
                  <td  width="5%" align="center"><?php echo $rs['shangjia_20_30'] ?></td>
                  <td  width="5%" align="center"><?php echo $rs['promo_price_g_30'] ?></td>
                  <td  width="5%" align="center"><?php echo $rs['shangjia_g_30'] ?></td>


                  <td  align="center"><?php echo $rs['promo_price_sum'] ?></td>
                  <td  align="center"><?php echo $rs['shangjia_sum'] ?></td>

                
              </tr>
              <?php } ?>
             <?php } ?>

          </tbody>
        </table>

        
      </div>
    </form>


  </div>
  <script src="<?php echo $staticUrl; ?>statics/js/common.js"></script>
  <script type="text/javascript">
    var td_length = $("td").length;
    for(var i=0;i<td_length;i++){
      if($("td").eq(i).html() == ''){
        $("td").eq(i).html('0');
      }
    }

    $(function(){
      //统计总和
      var html = $(".rowspan").parent().eq(0).html();
      $("#tbody").append("<tr>"+html+"</tr>");
      var obj = $("#tbody tr").last();

      var obj_tr = $("tr[data_admin_id]");
      var len = obj_tr.eq(0).find('td:not(.rowspan)').length;
      var length = obj_tr.length;
      var arr = [];
      for(var i=0;i<len;i++){
        for(var j = 0;j<length;j++){
          if(!arr[i]){
            arr[i] = 0;
          }
           arr[i] = arr[i] + parseInt(obj_tr.eq(j).find('td:not(.rowspan)').eq(i).html());       
        }
      }
      for(var k = 0;k<len;k++){
        obj.find('td:not(.rowspan)').eq(k).html(arr[k]);
      }

      var length = $("#tbody tr").find('td.rowspan').length;

      var len = 0;
      for(var i=0;i<length;i++){
        var shu = parseInt($("#tbody tr").find('td.rowspan').eq(i).html());
        if(shu){
          len = len + shu;
        }
      }   

      obj.find('td:eq(2)').html(len);
      obj.find('td:eq(0)').html('');
      obj.find('td:eq(1)').html('');

    })
  </script>
</body>
</html>